<template>
  <div>
    <el-card>
      <div class="card">
        <div class="lable">学科：</div>
        <div class="text">
          <p :class="textName === '全部' ? 'textColor': '' " @click="selectFn({subjectName:'全部',subjectId:''})">全部</p>
          <p :class="textName === item.subjectName ? 'textColor': '' " @click="selectFn(item)" v-for="(item,index) in subjectList" :key="item.subjectId">{{ item.subjectName }}</p>
        </div>
      </div>
    </el-card>
    <el-card class="card_box">
      <div class="card">
        <div class="lable">排序：</div>
        <div class="text">
          <p :class="sortName === '全部' ? 'textColor': '' " @click="sortSelectFn('全部')">全部</p>
          <p :class="sortName === '最新' ? 'textColor': '' " @click="sortSelectFn('最新')">最新</p>
          <p :class="sortName === '最热' ? 'textColor': '' " @click="sortSelectFn('最热')">最热</p>
        </div>
      </div>
    </el-card>
    <div class="nowSearch">当前搜索：<span class="nowSearch_span textColor">{{textName}}</span></div>
  </div>
</template>

<script>
import { getSubject } from '@/api/subject'
export default {
  data() {
    return {
      textName: '全部',
      subjectId: '',
      sortName: '全部',
      resSort: 0,
      subjectList: []
    }
  },
  mounted() {
    getSubject().then(res => {
      this.subjectList = res.data
    })
  },
  methods: {
    sortSelectFn(value) {
      this.sortName = value
      if (value === '最新') {
        this.resSort = 2
      } else if (value === '最热') {
        this.resSort = 1
      }
      this.$store.commit('post/setSearchParms', {
        subjectId: this.subjectId,
        sortNumber: this.resSort
      })
    },
    selectFn(item) {
      this.textName = item.subjectName
      this.subjectId = item.subjectId
      this.$store.commit('post/setSearchParms', {
        subjectId: this.subjectId,
        sortNumber: this.resSort
      })
    }
  }
}
</script>

<style lang="less" scoped>
.card_box {
  margin-top: 5px;
}
.textColor {
  font-weight: 700;

  color: black;
}
.card {
  display: flex;
  .lable {
    color: black;
    font-weight: 700;
    font-size: 16px;
  }
  .text {
    display: flex;
    align-items: center;
    color: #909399;
    .textColor {
      font-weight: 700;

      color: black;
    }
    p {
      padding-left: 5px;
      cursor: pointer;
    }
  }
}
.nowSearch {
  padding: 5px 0;
  .nowSearch_span {
    color: black;
  }
}
</style>